/*******************************************************************************
 * Copyright (c) 2012 Daniele Parisi.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Daniele Parisi
 *     neb.inf@gmail.com
 *     http://www.danieleparisi.com/
 ******************************************************************************/
package org.jxreport.core.views.chart.pie;

import org.jxreport.core.Table;
import org.jxreport.core.XMLUtils;
import org.jxreport.core.XMLValues;
import org.w3c.dom.Element;

public class Series {

	String title;
	String value;
	
	public Series(Element seriesElement) {
		this.setTitle(XMLUtils.getTextValue(seriesElement, XMLValues.TITLE));
		this.setValue(XMLUtils.getTextValue(seriesElement, XMLValues.VALUE));
	}
	
	public Series(Element seriesElement, Table table) {
		this.setTitle(XMLUtils.getTextValue(seriesElement, XMLValues.TITLE));
		
		int xIndex = Integer.valueOf(XMLUtils.getTextValue(seriesElement, XMLValues.X_INDEX));
		int yIndex = Integer.valueOf(XMLUtils.getTextValue(seriesElement, XMLValues.Y_INDEX));
		
		Object value = table.get(xIndex).get(yIndex).getValue();
		if(value instanceof String)
			this.setValue((String)value);
		else if(value instanceof Double)
			this.setValue(String.valueOf((Double)value));
	}
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
}
